package view;

import java.text.ParseException;
import java.util.Scanner;

import model.Task;

import checking.InputValidation;
import controller.ControllerForDB;

public class MenuHelperForTask {

	static InputValidation oValidation = new InputValidation();
	static ControllerForDB controller = new ControllerForDB();
	static Task addedTaskToDB = null;
	static MenuHelperForResource oResourceHelper = new MenuHelperForResource();
	
	public  void addTaskToActivity(int activityId) throws ParseException {

		System.out.println("Please enter the description of the task;\n");
		Scanner taskDesc = new Scanner(System.in);
		String taskDescription = taskDesc.next();
		System.out.println("\n");

		try {

			oValidation.validateString(taskDescription);

		} catch (Exception e) {
			System.out.println(e.getMessage());
			System.out.println("Please enter valid entries!");

		}

		System.out.println("Please enter the start date of the task;\n");
		Scanner taskStartDate = new Scanner(System.in);
		String taskSDate = taskStartDate.next();
		System.out.println("\n");
		if (!(oValidation.date_control(taskSDate))) {
			System.out.println("Invalid date entry!!!");

		}

		System.out.println("Please enter the estimated hours of the task;\n");
		Scanner taskEstHours = new Scanner(System.in);
		int taskEsHours = taskEstHours.nextInt();
		System.out.println("\n");

		System.out.println("Please enter the deliverable of the task;\n");
		Scanner taskDel = new Scanner(System.in);
		String taskDeliverable = taskDel.next();
		System.out.println("\n");
		try {

			oValidation.validateString(taskDeliverable);

		} catch (Exception e) {
			System.out.println(e.getMessage());
			System.out.println("Please enter valid entries!");

		}

		addedTaskToDB = controller.addTaskToDB(taskDescription, taskSDate,
				taskEsHours, taskDeliverable, activityId);

		System.out
				.println(addedTaskToDB.toString()
						+ " task is added to your activity. If you want to continue there are your options;\n");
		System.out.println("1- Add Resource\n");
		System.out.println("2- Exit");

		Scanner response4 = new Scanner(System.in);
		String fourthResp = response4.next();
		int taskId = oValidation.checkInteger(fourthResp);
		oValidation.validateResponse(taskId, 2);

		if (taskId == 1) {
			oResourceHelper.assignResourceToTask(taskId);
		}
	}

	public  void removeTaskFromActivity(int actId) {

		System.out.println("Your tasks are\n;");
		controller.getAllTask(actId);

		System.out
				.println("Please enter the number of task you want to remove;\n");
		Scanner tId = new Scanner(System.in);
		int taskId = tId.nextInt();

		controller.removeTaskFromDB(taskId);

	}

	public  void updateTaskFromActivity(int actId) {

		System.out.println("Your tasks are;\n");
		controller.getAllTask(actId);

		System.out
				.println("Please enter the id of  task that you want to update");
		Scanner tId = new Scanner(System.in);
		int taskId = tId.nextInt();

		System.out.println("Please enter the description of the task;\n");
		Scanner tDesc = new Scanner(System.in);
		String taskDesc = tDesc.next();

		System.out.println("Please enter the start date of the task;\n");
		Scanner tSDate = new Scanner(System.in);
		String taskStartDate = tSDate.next();

		System.out.println("Please enter the estimated hours of the task;\n");
		Scanner tEst = new Scanner(System.in);
		int taskEstHours = tEst.nextInt();

		System.out.println("Please enter the exact hours of the task;\n");
		Scanner tExact = new Scanner(System.in);
		int taskExHours = tExact.nextInt();

		System.out.println("Please enter the deliverable of the task;\n");
		Scanner tDel = new Scanner(System.in);
		String taskDel = tDel.next();

		controller.updateTaskFromDB(taskId, taskDesc, taskStartDate,
				taskEstHours, taskExHours, taskDel);

	}
}
